-
-
Notifications
You must be signed in to change notification settings - Fork 205
feat(userReports): add /api/v2/user-reports/
endpoint for superusers DEV-232 DEV-899
#6243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… caculated fields to the seralizer, add pagination, and only allow superusers to access endpoint
…ze-queries-for-subscriptions
507182e
to
3f421d1
Compare
noliveleger
requested changes
Sep 17, 2025
noliveleger
reviewed
Sep 18, 2025
5e61538
to
b8bd62d
Compare
…om:kobotoolbox/kpi into dev-899-optimize-queries-for-subscriptions
944c064
to
214b7ad
Compare
…ze-queries-for-subscriptions
…ze-queries-for-subscriptions
b644fdf
to
a9498f1
Compare
/api/v2/user-reports/
endpoint for superusers DEV-232 DEV-899/api/v2/user-reports/
endpoint for superusers DEV-232 DEV-899
noliveleger
approved these changes
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
rajpatel24
added a commit
that referenced
this pull request
Oct 16, 2025
…ts` endpoint DEV-287 DEV-233 (#6342) ### 📣 Summary Adds robust filtering and ordering capabilities to the `/api/v2/user-reports` API endpoint, enabling users and admins to query large user datasets efficiently by date, usage metrics, and subscription attributes, all backed by the optimized materialized view for scalable performance on millions of records. ### 📖 Description This PR introduces the filtering and ordering layer for the `/api/v2/user-reports` endpoint, built on top of the existing materialized view (`user_reports_userreportsmv`) that aggregates user-level billing and usage data. Also, added targeted indexes in `0003_add_user_reports_mv_indexes.py` on high-cardinality numeric and timestamp columns to support range queries without full table scans. Examples of usage: - Filter by username (case-insensitive, starts with): `/api/v2/user-reports/?q=username__icontains:raj` - Filter by email (case-insensitive, starts with): `/api/v2/user-reports/?q=email:[email protected]` - Filter by total storage bytes (greater than or equal to): `/api/v2/user-reports/?q=service_usage__total_storage_bytes__gte:1` - Filter by total storage bytes (less than or equal to): `/api/v2/user-reports/?q=service_usage__total_storage_bytes__lte:1` --- Part of #6243 --------- Co-authored-by: RuthShryock <[email protected]> Co-authored-by: Olivier Léger <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📣 Summary
Add a new superuser-only endpoint,
/api/v2/user-reports/
, to access and filter all user usage data.💭 Notes
user_reports
refresh_user_report_snapshots
runs every 30 minutes and works to update the data in batches📖 Description
This PR introduces a new endpoint
/api/v2/user-reports
that provides detailed information about users, including their personal details, metadata, organization info, subscriptions, usage statistics, and computed balances. It supports flexible nested filtering, allowing queries like:To handle a large user base, the endpoint leverages a PostgreSQL materialized view that aggregates user-related data for fast retrieval. Since some data (like usage and submissions) lives in another database, a periodic Celery task
refresh_user_report_snapshots
was added to pre-compute and store this data in a newBillingAndUsageSnapshot
table. The materialized view references this snapshot for further computations. ABillingAndUsageSnapshotRun
table was also added to track each run and safely resume interrupted jobs.👀 Preview steps
user_reports
/api/v2/user-reports/
and get a 403 Forbidden errorrefresh-user-report-snapshot
/api/v2/user-reports/
and get 200 with all the users and data